package com.fouram.core.enums;

import lombok.Getter;

/**
 * 操作符枚举
 * @author liupeng
 */
public enum OperationEnum {

	ADD( "+"){
		@Override
		public double apply(double x, double y) {
			return x + y;
		}
	},
	SUBTRACT( "-"){
		@Override
		public double apply(double x, double y) {
			return x - y;
		}
	},
	MULTIPLY( "*"){
		@Override
		public double apply(double x, double y) {
			return x * y;
		}
	},
	DIVISION( "/"){
		@Override
		public double apply(double x, double y) {
			return x / y;
		}
	};

	@Getter
	private final String symbol;
	OperationEnum(String symbol){
		this.symbol = symbol;
	}
	public abstract double apply(double x,double y);

	public static OperationEnum getEnum(String symbol) {
		for (OperationEnum it : OperationEnum.values()) {
			if (it.getSymbol().equals(symbol)) {
				return it;
			}
		}
		return null;
	}
}